<?

/* 
 * View implementation for the GameView controller
 */ 

?>
<table id="action_list">
<?
  $lauf = 0;
  foreach($this->model->getActionListForZone($this->selectedAction) as $act)
  if ($this->model->printPrerequisites($act['a_prereqs'], $this->character, true) 
    && $lauf == 0
    && getDefault($act['properties']['subtype'], $act['a_type']) == 'C')
  {
    $lauf++;
    $mobObjects = array();
    $deadPool = array();
    $groupDamage = array();
    global $groupDamage;
    
    if ($act['properties']['combatmode'] == 'party')
    {
      $this->myGroup = $this->party->loadGroup($this->user->localRecord['u_key']);
      foreach($this->myGroup as $mem)
      if ($mem['p_hp'] > 0) {
        $mobObjects['char.'.$mem['c_key']] = new CharacterModel('', $this, $mem['c_key']);
        $mobObjects['char.'.$mem['c_key']]->stats['enemy'] = 'mob';
        $mobObjects['char.'.$mem['c_key']]->stats['HP.current'] = $mem['p_hp'];
        unset($mobObjects['char.'.$mem['c_key']]->stats['hp.current']);
        if ($mobObjects['char.'.$mem['c_key']]->stats['weapon.damage']<$this->character->level)
          $mobObjects['char.'.$mem['c_key']]->stats['weapon.damage'] = $this->character->level;
      }
    }    
    makeParticipantsFromAction($mobObjects, $act, $this->character);
    
    $icon = getDefault($act['mobs'][0]['c_icon'], $act['a_icon']);
    
    ?><tr>
        <td valign="top"><img width="150" src="img/<?= getDefault($icon, 'evilgrin') ?>.png"/>
          <br/><div><ul style="padding: 10px;">
            <?= DisplayAttackerList($mobObjects) ?>
          </ul></div>
        </td>
        <td valign="top">    
          <h2><?= $act['a_name'] ?></h2> 
          <br/> 
          <div class="action_intro">
            <?= nl2br($act['a_text']) ?><br/>
          </div>
          <br/>
          <div class="action_fightlog"><?
          
          ob_start();
          
          ?><input type="button" name="action!" id="actbtn1" value="OK" onclick="$('#actbtn1').fadeTo('slow', 0.3); document.location='<?= actionUrl('index', 'game') ?>';"/><?
          
          if ($act['a_type'] == 'C' && $this->character->getCharacterStat('AP') > getDefault($act['a_cost'], 1) && $this->character->getCharacterStat('HP') > 0)
          {
          ?><input type="button" name="action!" id="actbtn2" value="do this again" onclick="$('#actbtn2').fadeTo('slow', 0.3); document.location='<?= actionUrl('act', 'game', 'id='.$_REQUEST['id']) ?>';"/><?
          }
          
          $act['afteraction'] = ob_get_clean();
          
          executeFight($mobObjects, $this->character, $act);
          
          ?>
          </div>
        </td>
      </tr><?
  }
  
  if ($act['properties']['combatmode'] == 'party')
    {
      foreach($this->myGroup as $mem)
      {
        $hp = getDefault($groupDamage['char.'.$mem['c_key']], $mem['p_hp']);
        $grpd = DB_GetDataset('parties', $mem['p_key']);
        $grpd['p_hp'] = $hp;
        DB_Updatedataset('parties', $grpd);
      }
    }    
?>
</table>
